﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class 实验三_3_6_b : System.Web.UI.Page
{
    StudentClassesDataContext db = new StudentClassesDataContext();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack) { return; }
        String id =  Request.QueryString["id"];

        var stu = db.Student.Where(x => x.id== id);
        var s = (from x in db.Student
                join c in db.Course
                on x.cid equals c.cid  
                where x.id == id
                select new
                {
                    x.id,
                    x.name,
                    x.sex,
                    x.sclass,
                    c.cid
                }).First();
        TextBox1.Text = s.id;
        TextBox2.Text = s.name;
        TextBox3.Text = s.sex=='0'? "女":"男";
        TextBox4.Text = s.sclass.ToString();
        DropDownList1.SelectedValue = s.cid;

    }

    protected void Button1_Click (object sender, EventArgs e)
    {
        var s = (from x in db.Student
                
                 where x.id == TextBox1.Text
                 select x).First();
        s.name = TextBox2.Text;
        s.sex = TextBox3.Text.Equals("男")? '1':'0';
        s.sclass = TextBox4.Text;
        s.cid = DropDownList1.SelectedValue;

        db.SubmitChanges();

    }
}